/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cayumapu;
import java.sql.*;
/**
 *
 * @author Kp4rz0
 */
public class conexion {
    Connection ConexionSql;
    Statement SqlStatement;
    ResultSet SqlResult;

    public conexion() {
    }

    public Connection getConnection() throws SQLException {

        ConexionSql = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");

            String puerto = "1521";
            String user   = "cayumapu";
            String pass   = "cayumapu";

            ConexionSql = DriverManager.getConnection("jdbc:oracle:thin:@localhost:" + puerto + ":XE", user, pass);
        } catch (ClassNotFoundException e){
            System.out.println("Error en el driver: " + e.getMessage());
        }
        return ConexionSql;

    }
    /* metodo que permite realizar una insercion en la bdd*/
    public boolean executeStatement(String pSqlQuery) throws SQLException {
        ConexionSql = getConnection();
        if(ConexionSql != null){
            SqlStatement = ConexionSql.createStatement();
            SqlStatement.executeUpdate(pSqlQuery);

            SqlStatement.close();
            ConexionSql.close();
            return true;
        }
        return false;
    }
    /* permite ejecutar una consulta (query) en la bdd*/
    public ResultSet ejecuteQuery(String pSqlQuery) throws SQLException {
        ConexionSql = getConnection();
        if(ConexionSql != null){
            SqlStatement = ConexionSql.createStatement();
            ResultSet Result = SqlStatement.executeQuery(pSqlQuery);

            return Result;
        }
        return null;
    }
    /*Metodo que cierra todas las conecciones*/

}
